package com.atguigu.controller;

import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author:hx
 * @DateTime:2022/9/26 18:44
 * @Description:
 */
@Controller
@RequestMapping("/dict")
public class DictController {
    @DubboReference
    private DictService dictService;

    @RequestMapping
    public String index(){
        return "dict/index";
    }

    /**
     * @Description 根据父节点id查询子节点信息
     * @param parentId:
     * @return: com.atguigu.result.Result
     */
    @RequestMapping("/findZnodes")
    @ResponseBody
    public Result findZnodes(@RequestParam(defaultValue = "0") Long parentId){
        List<Map<String,Object>> znodes = dictService.findZnodes(parentId);
        return Result.ok(znodes);
    }

    @RequestMapping("/findDictListByParentId/{parentId}")
    @ResponseBody
    public Result findDictListByParentId(@PathVariable("parentId") Long parentId){
        List<Dict> dictList = dictService.findDictListByParentId(parentId);
        return Result.ok(dictList);
    }
}
